<script>
	export default {
		onLoad: function(e) {
			if (e.userId) {
				uni.setStorageSync('InvitedCode', e.userId)
			}
			if (e.InvitedCode) {
				uni.setStorageSync('InvitedCode', e.InvitedCode)
			}


		},
		// 进来默认登录
		onLaunch: function() {
			console.log('App Launch')


			
			// 获取到token
			// this.wxlogin()
			// this.getLocationPermission()
			console.log('App Show')

		},
		onShow: function() {
			
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods: {
			
			wxlogin() {
				var _this = this;
				uni.removeStorageSync('token');
				uni.removeStorageSync('clientID')
				uni.login({
					provider: 'weixin',
					success: function(loginRes) {
						console.log(loginRes)
						// return;
						// 在这里处理登录成功后的逻辑，如获取用户信息等  
						_this.$http({
							url: _this.$myApi.xcxLogin,
							method: 'POST',
							hideLoading: true,
							data: {
								"xcxCode": loginRes.code,
								"clientId": "25e5f3649dded6a3345ef8ee6359cda0",
								"grantType": "xcx",
								"appid": "wx767edd216cfa44e2"
							},
							success: res => {

								// console.log('是否显示----------', res)
								uni.setStorage({
									key: 'isLoginShow',
									data: res.data,
									success: function() {}
								});
								uni.removeStorageSync('openId');
								// 存取token
								uni.setStorageSync('token', 'Bearer ' + res.data
									.access_token)
								uni.setStorageSync('clientID', res.data
									.client_id)
								uni.setStorageSync('openId', res.data)

								if (res.code == 200) {
									if (res.data.phoneFlag == 1) {

										let wxMsg = {
											nickName: res.data.userName,
											avatarUrl: res.data.avatar,
											phone: res.data.phonenumber,
										}
										try {
											uni.removeStorageSync('wxLogin')
											uni.setStorageSync('wxLogin', wxMsg);
											// console.log(uni.getStorageSync('wxLogin'))
										} catch (error) {
											// console.log('存储失败', error);  
										}



										setTimeout(() => {
											uni.switchTab({
												url: '/pages/myHome/index'
											});
										}, 200)
									} else {
										uni.switchTab({
											url: '/pages/newMy/index'
										})
										uni.removeStorageSync('userSInfo');
										uni.setStorageSync('userSInfo', 1);

									}

								}

							},
							fail: err => {
								// console.log(err, 3333333333)
							},
							complete: e => {
								// uni.navigateTo({
								// 	url: '/pages/orderManagement/index'
								// })
							}
						})
					}
				});
			}

		}

	}
</script>

<style lang="scss">
	@import "uview-ui/index.scss";

	// ios底部安全距离-padding
	.savepadding {
		padding-bottom: constant(safe-area-inset-bottom);
		padding-bottom: env(safe-area-inset-bottom);
		box-sizing: content-box;
	}

	// ios底部安全距离-bottom
	.savebottom {
		bottom: constant(safe-area-inset-bottom);
		bottom: env(safe-area-inset-bottom);
	}
</style>